<td> 

<!----------------------------PHP---------------------------------------->

<?php

$carrierList = array("Bell"=>"@txt.bell.ca","Bell Mobility"=>"@txt.bellmobility.ca","Fido"=>"@sms.fido.ca","Rogers"=>"@pcs.rogers.com","Telus"=>"@msg.telus.com","Virgin Mobile"=>"@vmobile.ca","Koodo Mobile"=>"@msg.koodomobile.com");
//print_r($carrierList);

$found=false;

/*if(isset($carIndex) && $carIndex!="")
{
	echo $carIndex;
}
else if(isset($carIndex) && $carIndex=="")
{
	echo "Index is empty";
}
else
{
	echo "No Index.";
}*/

if(isset($person) && isset($profile) && isset($cars) && isset($notifications))
{
			$found=true;
			//print_r($person);
			//print_r($profile);
			//print_r($cars);
			//print_r($notifications);	
	
	//print_r($person);
	
	echo "<script>var tempSearchInput = ". $person->getCellPhoneNumber() .";</script>";	
	
}

function isChecked($note,$notifications)
{
	
	$checked = false;

		foreach($notifications as $a)
		{
			if($a->getNotificationId() == $note)
			{
				$checked = true;
			}
				
		}


	return $checked;
}

?>

<!--------------------------------Javascript------------------------------>
<script>

function resetProfile()
{	

	document.getElementById("profileAction").value="";

	/*button*/
	document.getElementById("createProfileBtn").value= "Create Profile";
	document.getElementById("createProfileBtn").disabled=false;
	document.getElementById("saveProfileBtn").disabled=true;
	document.getElementById("editProfileBtn").disabled=true;
	document.getElementById("deleteProfileBtn").disabled=true;
	document.getElementById("searchProfileBtn").disabled=false;	
	
	defaultValue();
	disableFieldsForCreate();
	resetCar();
	
	document.getElementById("createCarBtn").disabled=true;
	
	
}

function resetCar()
{
	
	document.getElementById("carAction").value="";
	document.getElementById("createCarBtn").value="Create Car";
	document.getElementById("createCarBtn").disabled=false;
	document.getElementById("carSelection").disabled=true;
	document.getElementById("saveCarBtn").disabled=true;
	document.getElementById("editCarBtn").disabled=true;
	document.getElementById("deleteCarBtn").disabled=true;
	
	
	document.getElementById("carMake").disabled=true;
	document.getElementById("carModel").disabled=true;
	document.getElementById("carYear").disabled=true;
	document.getElementById("lastOilChanged").disabled=true;
	
	clearCarInputs();
	
}

function clearCarInputs()
{
	document.getElementById("carSelection").value="";
	document.getElementById("carMake").value="";
	document.getElementById("carModel").value="";
	document.getElementById("carYear").value="";
	document.getElementById("lastOilChanged").value="";	
	document.getElementById("carHistory").value="";
}



function defaultValue()
{
	document.getElementById("c_sex_male").checked=false;
	document.getElementById("c_sex_female").checked=false;
	document.getElementById("note1_no").checked=true;	
	document.getElementById("note2_no").checked=true;	
	document.getElementById("note3_no").checked=true;	
	document.getElementById("note0_no").checked=true;
	document.getElementById("sendNoteToCell").checked=false;
	document.getElementById("sendNoteToEmail").checked=false;
	
	document.getElementById("c_id").value = "";
	document.getElementById("c_fname").value = "";
	document.getElementById("c_lname").value = "";
	document.getElementById("c_hphone").value = "";
	document.getElementById("c_cphone").value = "";
	document.getElementById("c_email").value = "";	
	
	document.getElementById("searchClientInput").value = "";	
	document.getElementById("carrierSelection").value = "-1";	
	
	

}



function enableFieldsForCreate()
{
	document.getElementById("searchClientInput").disabled=true;
	
	document.getElementById("c_id").disabled=true;
	document.getElementById("c_sex_male").disabled=false;
	document.getElementById("c_sex_female").disabled=false;
	document.getElementById("c_fname").disabled=false;
	document.getElementById("c_lname").disabled=false;
	document.getElementById("c_hphone").disabled=false;
	document.getElementById("c_cphone").disabled=false;
	document.getElementById("carrierSelection").disabled=false;
	document.getElementById("c_email").disabled=false;
	
	document.getElementById("note1_yes").disabled=false;
	document.getElementById("note1_no").disabled=false;
	document.getElementById("note2_yes").disabled=false;
	document.getElementById("note2_no").disabled=false;
	document.getElementById("note3_yes").disabled=false;
	document.getElementById("note3_no").disabled=false;
	
	document.getElementById("sendNoteToCell").disabled=false;
	document.getElementById("sendNoteToEmail").disabled=false;
	
	document.getElementById("note0_yes").disabled=false;
	document.getElementById("note0_no").disabled=false;
	
}

function disableFieldsForCreate()
{
	document.getElementById("searchClientInput").disabled=false;
	
	document.getElementById("c_id").disabled=true;
	document.getElementById("c_sex_male").disabled=true;
	document.getElementById("c_sex_female").disabled=true;
	document.getElementById("c_fname").disabled=true;
	document.getElementById("c_lname").disabled=true;
	document.getElementById("c_hphone").disabled=true;
	document.getElementById("c_cphone").disabled=true;
	document.getElementById("carrierSelection").disabled=true;
	document.getElementById("c_email").disabled=true;
	
	document.getElementById("note1_yes").disabled=true;
	document.getElementById("note1_no").disabled=true;
	document.getElementById("note2_yes").disabled=true;
	document.getElementById("note2_no").disabled=true;
	document.getElementById("note3_yes").disabled=true;
	document.getElementById("note3_no").disabled=true;
	
	document.getElementById("sendNoteToCell").disabled=true;
	document.getElementById("sendNoteToEmail").disabled=true;
	
	document.getElementById("note0_yes").disabled=true;
	document.getElementById("note0_no").disabled=true;

}

function createProfile()
{

	if(document.getElementById("profileAction").value=="")
	{
		document.getElementById("profileAction").value="create";
		document.getElementById("createProfileBtn").value= "Cancel Create";
				
		/*button*/
		document.getElementById("createProfileBtn").disabled=false;
		document.getElementById("saveProfileBtn").disabled=false;
		document.getElementById("editProfileBtn").disabled=true;
		document.getElementById("deleteProfileBtn").disabled=true;
		document.getElementById("searchProfileBtn").disabled=true;	
		document.getElementById("searchClientInput").value = "";
		
		//document.getElementById("createCarBtn").disabled=false;
		
		
		/*field*/
		enableFieldsForCreate();
		
		/*value*/
		defaultValue();
		
		/*car*/
		resetCar();
		document.getElementById("createCarBtn").disabled=true;
		
		
		
	}
	else if(document.getElementById("profileAction").value=="create")
	{
		resetProfile();		
	}	
}


function editProfile()
{


	if(document.getElementById("profileAction").value=="")
	{
		document.getElementById("profileAction").value="edit";
		
		/*button*/
		document.getElementById("editProfileBtn").value = "Cancel Edit";
		document.getElementById("createProfileBtn").disabled = true;
		document.getElementById("saveProfileBtn").disabled = false;
		document.getElementById("deleteProfileBtn").disabled = true;
		
		/*field*/
		enableFieldsForCreate();

	}
	else if(document.getElementById("profileAction").value=="edit")
	{
		document.getElementById("profileAction").value="search";
		document.getElementById("searchClientInput").disabled = false;
		document.getElementById("searchClientInput").style.color = "white";
		document.getElementById("searchClientInput").value = tempSearchInput;
		document.profileForm.submit();
	}	



}


function createCar()
{
	if(document.getElementById("carAction").value == "")
	{
		resetCar();
		document.getElementById("carSelection").innerHTML = "";
		document.getElementById("carAction").value="create";
		
		document.getElementById("saveCarBtn").disabled=false;
		document.getElementById("createCarBtn").value="Cancel Create";
		
		document.getElementById("carSelection").disabled=true;
		document.getElementById("carMake").disabled=false;
		document.getElementById("carModel").disabled=false;
		document.getElementById("carYear").disabled=false;
		document.getElementById("lastOilChanged").disabled=false;
		document.getElementById("carHistory").disabled=false;	
		
		
		
					
		
	}
	else if(document.getElementById("carAction").value=="create")
	{
		resetCar();
		document.getElementById("carAction").value="cancel";
		document.profileForm.submit();
		
		
	}
}

function searchProfile()
{
	document.getElementById("profileAction").value="search";
	document.profileForm.submit();
}

function loadCarInfo()
{


	var carSelection = document.getElementById("carSelection");
	var selectedCarIndex = carSelection.options[carSelection.selectedIndex].value;

	//alert(selectedCarIndex + " Here");
	
	if(selectedCarIndex >= 0)
	{
		document.getElementById("selectedCarIndex").value = selectedCarIndex;
		document.getElementById("profileAction").value = "setSelectedCarIndex";
		document.profileForm.submit();
	}
	else
	{	
		document.getElementById("carMake").disabled=true;
		document.getElementById("carModel").disabled=true;
		document.getElementById("carYear").disabled=true;
		document.getElementById("lastOilChanged").disabled=true;
		document.getElementById("carHistory").disabled=true;
		
		document.getElementById("carMake").value="";
		document.getElementById("carModel").value="";
		document.getElementById("carYear").value="";
		document.getElementById("lastOilChanged").value="";	
		document.getElementById("carHistory").value="";
		
		document.getElementById("saveCarBtn").disabled=true;
		document.getElementById("editCarBtn").disabled=true;
		document.getElementById("deleteCarBtn").disabled=true;
		
	}
}

function editCar()
{
	if(document.getElementById("carAction").value=="")
	{	
		document.getElementById("carAction").value="edit";
		
		/*button*/
		document.getElementById("editCarBtn").value = "Cancel Edit";
		document.getElementById("createCarBtn").disabled = true;
		document.getElementById("saveCarBtn").disabled = false;
		document.getElementById("deleteCarBtn").disabled = true;
		
		/*field*/
		document.getElementById("carMake").disabled=false;
		document.getElementById("carModel").disabled=false;
		document.getElementById("carYear").disabled=false;
		document.getElementById("lastOilChanged").disabled=false;
		document.getElementById("carHistory").disabled=false;
		
		
		
		
	}
	else if(document.getElementById("carAction").value=="edit")
	{
		document.getElementById("carAction").value="";
		document.getElementById("carAction").value="cancel";
		document.profileForm.submit();
	}
	
}

function deleteCar()
{
	document.getElementById("carAction").value = "delete";
	document.profileForm.submit();
}

function saveCar()
{
	if(document.getElementById("profileAction").value == "edit" || document.getElementById("profileAction").value == "delete")
	{
	var carSelection = document.getElementById("carSelection");
	var selectedCarIndex = carSelection.options[carSelection.selectedIndex].value;
	document.getElementById("selectedCarIndex").value = selectedCarIndex ;
	}
	
	document.profileForm.submit();
	
	

}

function deleteProfile()
{
	document.getElementById("profileAction").value = "delete";
	document.profileForm.submit();
}

function saveProfile()
{

	var carrierSelection = document.getElementById("carrierSelection");
	var selectedCarrier = carrierSelection.options[carrierSelection.selectedIndex].value;
	
	document.getElementById("cell_phone_carrier").value = selectedCarrier;
	
	//alert(document.getElementById("cell_phone_carrier").value);
	
	document.profileForm.submit();
}

</script>
<!------------------------------------------------------------------------>



<!---------------------------------CODE----------------------------------->
<form name="profileForm" action="#" method="post">
	<table class="content" >
	
	<tr>	
		<td colspan="3">
			Client Profile:   
			<input type="text" id="searchClientInput" name="searchClientInput" placeholder="Enter phone number">  
			<input type="button" id="searchProfileBtn" onclick="searchProfile()" value="Search"> 
			<input type="button" id="deleteProfileBtn" onclick="deleteProfile()" value="Delete Profile" style="float:right" <?php if($found){echo "enabled";}else{echo "disabled";}?>>
			<input type="button" id="editProfileBtn" onclick="editProfile()" value="Edit Profile" style="float:right" <?php if($found){echo "enabled";}else{echo "disabled";}?>>
			<input type="button" id="saveProfileBtn" onclick="saveProfile()" value="Save Profile" style="float:right" disabled>
			<input type="button" id="createProfileBtn" value="Create Profile" onclick="createProfile()" style="float:right">	
			<input type="hidden" id="profileAction" name="profileAction" value="">
			<input type="hidden" id="selectedCarIndex" name="selectedCarIndex" value="">
			<input type="hidden" id="profileId" name="profileId" value="<?php if(isset($person)){ echo $person->getHomePhoneNumber();}?>">
			<input type="hidden" id="personId" name="personId" value="<?php if(isset($person)){ echo $person->getPersonId();}?>">
			<input type="hidden" id="client_id" name="client_id" value="<?php if(isset($profile)){ echo $profile->getProfileId();}?>">
			<input type="hidden" id="carSelectedId" name="carSelectedId" value="">
			<input type="hidden" id="cell_phone_carrier" name="cell_phone_carrier" value="">
			
		</td>		
	</tr>
	
	<tr>
	
	<td style="border: 0px solid black; height:100%">
		<div class="round2Profile">
		<table style="border: 0px solid black; width:100%;">

			<tr><td><b><u>Client Info</u></b><br></td></tr>
			<tr><td>Client Id:</td><td><input type="text" id="c_id" name="c_id" value="<?php if($found){echo $profile->getProfileId();} ?>" disabled></td></tr>
			
			<tr><td>Gender<span class="red">*</span>:</td><td><input type="radio" name="c_sex" id="c_sex_male" value="Male" disabled>Male<input type="radio" name="c_sex" id="c_sex_female" value="Female" disabled>Female</td></tr>
			<?php
				if($found)
				{
					if($person->getGender()=="M")
					{
						echo "<script>document.getElementById('c_sex_male').checked=true;</script>";
						
					}
					else
					{
						echo "<script>document.getElementById('c_sex_female').checked=true;</script>";
					}
				}
			?>
			
			<tr><td>First Name<span class="red">*</span>:</td><td><input type="text" id="c_fname" name="c_fname" value="<?php if($found){echo $person->getFirstName();} ?>" disabled></td></tr>
			<tr><td>Last Name<span class="red">*</span>:</td><td><input type="text" id="c_lname" name="c_lname" value="<?php if($found){echo $person->getLastName();} ?>" disabled></td></tr>
			<tr><td>Home Phone<span class="red">*</span>:</td><td><input type="text" id="c_hphone" name="c_hphone" placeholder="1###-###-####" value="<?php if($found){echo $person->getHomePhoneNumber();} ?>" disabled></td></tr>
			<tr><td>Cell Phone<span class="red">*</span>:</td><td><input type="text" id="c_cphone" name="c_cphone" placeholder="1###-###-####" value="<?php if($found){echo $person->getCellPhoneNumber();} ?>" disabled></td></tr>
			<tr><td>Cell Phone Carrier:</td>
			<td>
			<select id="carrierSelection" name="carrierSelection" disabled>	
		
				<?php 
					
					$selected="";
						
					echo "<option value='-1'></option>";
						
					foreach($carrierList as $carrier=>$carrier_value)
					{
						if(isset($person) && $person->getCellPhoneCarrier() != null)
						{
							if (stristr($person->getCellPhoneCarrier(), $carrier_value))
							{
								$selected = "selected";
							}
							else
							{
								$selected = "";
							}
						}
						
						echo "<option value='".$carrier."' ".$selected.">".$carrier."</option>";
					}
				?>
					
			</select>
			</td></tr>
			<tr><td>Email:</td><td><input type="text" id="c_email" name="c_email" value="<?php if($found){echo $person->getEMail();} ?>" disabled></td></tr>
			
			<tr><td><b><u>Notification</u></b></td></tr>
			<tr><td>Appointment Reminder</td>      <td><input type="radio" id="note1_yes" value="Yes" name="note1" <?php if($found){if(isChecked(1,$notifications)){echo "checked";}} ?> disabled>Yes<input type="radio" id="note1_no" value="No" name="note1" <?php if($found){if(!isChecked(1,$notifications)){echo "checked";}}else{echo "checked";} ?> disabled>No</td></tr>
			<tr><td>Maintenance Notification</td>  <td><input type="radio" id="note2_yes" value="Yes" name="note2" <?php if($found){if(isChecked(2,$notifications)){echo "checked";}} ?> disabled>Yes<input type="radio" id="note2_no" value="No" name="note2" <?php if($found){if(!isChecked(2,$notifications)){echo "checked";}}else{echo "checked";} ?> disabled>No</td></tr>
			<tr><td>Promotional Notification</td>  <td><input type="radio" id="note3_yes" value="Yes" name="note3" <?php if($found){if(isChecked(3,$notifications)){echo "checked";}} ?> disabled>Yes<input type="radio" id="note3_no" value="No" name="note3" <?php if($found){if(!isChecked(3,$notifications)){echo "checked";}}else{echo "checked";} ?> disabled>No</td></tr>
			<tr><td>Send Notification to:</td><td><input type="checkbox" id="sendNoteToCell" name="sendNoteToCell" <?php if($found && isset($profile)){if($profile->getSendToCellPhone() == 1){echo "checked";} }?> disabled>Cell Phone<br></td></tr>
			<tr><td></td>                     <td><input type="checkbox" id="sendNoteToEmail" name="sendNoteToEmail" <?php if($found && isset($profile)){if($profile->getSendToEmail() == 1){echo "checked";} }?> disabled>Email<br></td></tr>

					
		</table></div>
	
	</td>
	
	
	<td style="border: 0px solid black; height:100%;"><div class="round2Profile">
		<table style="border: 0px solid red; width:100%;">
					
			<tr><td><b><u>Storage</u></b></td></tr>
			<tr><td>Winter Tires Set<br><br><br></td>
			<td><input type="radio" id="note0_yes" name="note0" value="Yes" <?php if($found){if($profile->getTireSetStored()!= 0){echo "checked";}}?> disabled>Yes<input type="radio" id="note0_no" name="note0" value="No" <?php if($found){if($profile->getTireSetStored()== 0){echo "checked";}}else{echo "checked";} ?> disabled>No<br><br><br></td></tr>
			
			<tr><td><b><u>Car(s) info</u></b><br></td></tr>
			<tr><td>Car:</td><td><select id="carSelection" onchange="loadCarInfo()" <?php if($found && isset($cars) && count($cars)!=0) {echo "enabled";}else{echo "disabled";}?>>
			
 			<?php
 				
 				
 				$mycount=0;
 				$isSelected = "";
 				
 				
 					
	 			if($found && isset($cars))
	 			{
	 				if(isset($cars) && count($cars)==1)
	 				{	
	 					echo "<script> document.getElementById('carSelectedId').value = ".$cars[0]->getCarId().";</script>";
	 					echo "<option value='0'>Car #".$cars[0]->getCarId()."-->".$cars[0]->getModel()."</option>";
	 					$carIndex = 0;
	 					$isSelected = "selected";
	 				}
	 			
	 				else if(isset($cars) && count($cars)>1)
	 				{	
	 				
	 					echo "<option value='-1'></option>";
	 					
	 					if(isset($carIndex) && $carIndex=="") // it prevents from offset while deleting a selected car
				 		{
							$carIndex = count($cars)-1; 				
				 		}	
	 					 			
			 			foreach($cars as $car)
			 			{
			 			
					 			
			 			    
			 			    //echo "<script>alert(".$car->getCarId().");</script>";
			 				
			 				if(isset($carIndex)&& $mycount == $carIndex)
			 				{
			 					//echo "<script>alert('Im In.');</script>";
			 				
			 					//echo "<script>alert(".$mycount.");</script>";
			 					//echo "<script>alert(".$carIndex.");</script>";
			 					
			 					//echo "<script>alert(".$car->getCarId().");</script>";
			 					
			 					$isSelected = "selected";
			 					
			 					echo "<script> document.getElementById('carSelectedId').value = ".$car->getCarId().";</script>";
			 					
			 				}
			 				else
			 				{
			 					$isSelected = "";
			 				}
			 				
			 				echo "<option value='".$mycount."' ".$isSelected.">Car #".$car->getCarId()."-->".$car->getModel()."</option>";
			 				
			 				
			 				
			 				$mycount++;
			 			}	 
			 						
	 				}
	 			}
	 			
 			?>

 			
			</select></td></tr>
			<tr><td>Make<span class="red">*</span>:</td><td><input type="text" id="carMake" name="carMake" value="<?php if(isset($carIndex) && count($cars)!=0){if($carIndex==""){$carIndex = count($cars)-1;}echo $cars[$carIndex]->getMake();}?>" disabled></td></tr>
			<tr><td>Model<span class="red">*</span>:</td><td><input type="text" id="carModel" name="carModel" value="<?php if(isset($carIndex) && count($cars)!=0){echo $cars[$carIndex]->getModel();}?>" disabled></td></tr>
			<tr><td>Year<span class="red">*</span>:</td><td><input type="text" id="carYear" name="carYear" value="<?php if(isset($carIndex) && count($cars)!=0){echo $cars[$carIndex]->getYear();}?>" disabled></td></tr>
			<tr><td>Last Oil Changed:</td><td><input type="text" id="lastOilChanged" name="lastOilChanged" value="<?php if(isset($carIndex) && count($cars)!=0){echo $cars[$carIndex]->getLastOilChangeDate();}?>" disabled></td></tr>
			<tr><td>(yyyy-mm-dd)<br><br></td><td></td></tr>	
							
			<tr>
			<input type="hidden" id="carAction" name="carAction" value="">
			<td style="text-align:center"><input type="button" id="createCarBtn" value="Create Car" onclick="createCar()" <?php if($found){echo "enabled";}else{echo "disabled";}?>></td>
			<td style="text-align:center"><input type="button" id="saveCarBtn" value="Save Car" onclick="saveCar()" disabled></td>
			</tr>
			
			<tr>
			<td style="text-align:center"><input type="button" id="editCarBtn" value="Edit Car" onclick="editCar()" <?php if(isset($carIndex) && count($cars)!=0){echo "enabled";}else{echo "disabled";}?>></td>
			<td style="text-align:center"><input type="button" id="deleteCarBtn" value="Delete Car" onclick="deleteCar()" <?php if(isset($carIndex) && count($cars)!=0){echo "enabled";}else{echo "disabled";}?>></td>
			</tr>
			
			<tr><td><br><br><br></td></tr>
			</table></div>
	</td>
	
	
	<td style="border: 0px solid black; height:100%;" ><div class="round2Profile">
		<table>
				<tr><td><b><u>Current Car History:</u></b><br><br></td></tr>					
				<tr><td><div style="overflow:hidden; overflow-y:auto; height:350px;"><textarea id ="carHistory" name="carHistory" rows="15" cols="30" disabled><?php if(isset($carIndex) && count($cars)!=0){echo $cars[$carIndex]->getCarHistory();}?></textarea></div></td></tr>	
		</table>
	</td>
		
	
	</tr>
	
	
	</table>
	
</form>
						
<!------------------------------------------------------------------------>
			
			</td>
		</tr>